package creational.prototype.clone;

/**
 * @Description: 原型模式测试类
 * @Author: lxt
 * @CreateDate: 2019/11/1
 **/
public class CloneTest {
    private static void loadCache() {
        AbstractMessage componentMessage = new ComponentMessage();

        Content request = new Content();
        AbstractMessage socketMessage = new SocketMessage();
        socketMessage.setContent(request);

        MessageCache.putMessage("component", componentMessage);
        MessageCache.putMessage("socket", socketMessage);
    }

    public static void main(String[] args) {
        loadCache();
        AbstractMessage componentMessage1 = MessageCache.getMessage("component");
        AbstractMessage componentMessage2 = MessageCache.getMessage("component");

        SocketMessage socketMessage1 = (SocketMessage) MessageCache.getMessage("socket");
        SocketMessage socketMessage2 = (SocketMessage) MessageCache.getMessage("socket");

        System.out.println("组件之间的消息是否是一个对象：" + (componentMessage1 == componentMessage2));
        System.out.println("WebSocket消息是否来自一个类：" + (socketMessage1.getClass() == socketMessage2.getClass()));
        System.out.println("WebSocket消息内容是否是一个对象：" + (socketMessage1.getContent() == socketMessage2.getContent()));
    }
}
